home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Jotto ][ 1.2 / source / Shell ƒ / sounds.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  1.4 KB  |  69 lines  |  [TEXT/MMCC]

  1. #include "sounds.h"
  2.  
  3. SndChannelPtr        myChannel;
  4. Handle                MySounds[NUM_SOUNDS];
  5. Boolean                gSoundToggle;
  6. Boolean                gSoundAvailable;
  7. Boolean                gSoundIsFinishedPlaying;
  8.  
  9. pascal void SoundIsComplete(SndChannelPtr theChannel, SndCommand theCmd);
  10.  
  11. void InitTheSounds(void)
  12. {
  13.     short            i;
  14.     
  15.     gSoundAvailable=(SndNewChannel(&myChannel, 0, 0L, 0L)==noErr);
  16.     if (gSoundAvailable)
  17.         CloseTheSoundChannel();
  18.     for (i=0; i<NUM_SOUNDS; i++)
  19.         MySounds[i]=0L;
  20. }
  21.  
  22. void DoSound(short whichSound, Boolean async)
  23. {
  24.     SndCommand            myCommand;
  25.     SndCallBackUPP        callbackProc=NewSndCallBackProc(SoundIsComplete);
  26.     
  27.     CloseTheSoundChannel();
  28.     
  29.     whichSound-=1000;
  30.     if ((gSoundToggle) && (gSoundAvailable))
  31.     {
  32.         if (!MySounds[whichSound])
  33.             MySounds[whichSound]=GetResource('snd ', whichSound+1000);
  34.         
  35.         if (MySounds[whichSound])
  36.         {
  37.             if (SndNewChannel(&myChannel, 0, 0L, callbackProc) != noErr)
  38.             {
  39.                 myChannel = 0;
  40.                 gSoundAvailable = FALSE;
  41.             }
  42.             else
  43.             {
  44.                 myChannel->userInfo = (long)&gSoundIsFinishedPlaying;
  45.                 SndPlay(myChannel, MySounds[whichSound], async);
  46.                 if (async)
  47.                 {
  48.                     myCommand.cmd=callBackCmd;
  49.                     myCommand.param1=myCommand.param2=0;
  50.                     SndDoCommand(myChannel, &myCommand, false);
  51.                 }
  52.             }
  53.         }
  54.     }
  55. }
  56.  
  57. pascal void SoundIsComplete(SndChannelPtr theChannel, SndCommand theCmd)
  58. {
  59.     *(Boolean*)(theChannel->userInfo) = TRUE;
  60. }
  61.  
  62. void CloseTheSoundChannel(void)
  63. {
  64.     if (myChannel)
  65.         SndDisposeChannel(myChannel, TRUE);
  66.     myChannel=0L;
  67.     gSoundIsFinishedPlaying=FALSE;
  68. }
  69.